const mongoose = require("mongoose")
//连接本地数据库
mongoose
    .connect('mongodb://yun88.top:45322/tea', {
        useNewUrlParser: true, //URL字符串解析器
        useUnifiedTopology: true //服务器的监事引擎
    })
    .then(() => {
        console.log('连接数据库成功')
    })
    .catch((err) => {
        console.log('数据库连接失败')
        console.log(err)
    })
//指定表规则
const Schema = mongoose.Schema
//对表结构的定义(required:是否必填)
const useSchema = new Schema({
    name: {
        type: String
    },
    content: {
        type: String
    },
    price:{
        type: Number
    },
    num:{
        type:Number
    },
    imgUrl:{
        type:String
    },
    id:{
        type:Number
    }
},{collection:'goods_list'})

//建表
const Goods = mongoose.model('goods', useSchema)
module.exports = Goods